$source_folder = %1
$site = %2
$project_name = %3
$certificate = %4
$certificate_privpass = %5

:: Setup project @ IIS Manager
New-Item IIS:\AppPools\$project_name 
Set-ItemProperty IIS:\AppPools\$project_name managedRuntimeVersion v4.0

New-Item IIS:\Sites\$project_name -bindings @{protocol="http"; bindingInformation="*:80:$project_name"} -physicalPath $source_folder -applicationPool $project_name

icacls $source_folder /grant "IIS APPPOOL\$project_name:(OI)(CI)(R)"

echo "127.0.0.1 $site" | Out-File -encoding ASCII -append c:\windows\system32\drivers\etc\hosts

:: Install certificate
$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
$pfx.Import("$certificate", "$certificate_privpass", "PersistKeySet")
$store = new-object System.Security.Cryptography.X509Certificates.X509Store("$project_name-certificate", "LocalMachine")
$store.Open("MaxAllowed")
$store.Add($pfx)
$store.Close()


New-Item IIS:\SslBindings\0.0.0.0!443 -thumbprint $pfx.Thumbprint -store "MY"
New-ItemProperty IIS:\Sites\www.rp.ciws -name Bindings -value @{protocol = "https"; bindingInformation="*:443:";
certificateStoreName="MY"; certificateHash=$pfx.Thumbprint}
